package logic

import (
	"context"
	"library/models/mysql"

	"library/library/internal/svc"
	"library/library/library"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCommentLogic {
	return &ListCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListCommentLogic) ListComment(in *library.ListCommentRequest) (*library.ListCommentResponse, error) {
	// todo: add your logic here and delete this line

	var comment []mysql.Comment
	mysql.DB.Debug().Where("activity_id = ?", in.ActivityId).Find(&comment)

	var commentList []*library.ListComment

	for _, m := range comment {
		list := library.ListComment{
			UserId:  m.UserId,
			Context: m.Context,
		}
		commentList = append(commentList, &list)
	}

	return &library.ListCommentResponse{List: commentList}, nil
}
